﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace Jy123.Web.Module.Venues
{
    public partial class ModuleRank : System.Web.UI.Page
    {
        private int userId;
        private int venuesId;
        protected string ModuleId;
        private Jy123.Model.Venues_Main venues;
        private Jy123.Model.Module_Main module;
        private Jy123.Model.Public_Level level;
        private Jy123.Model.User_Main user;
        private string[] strContent = { "我的赛场", "赛场信息", "比赛实况", "赛场设备", "赛场排行", "赛场维护", "商业活动" };
        private string[] strCss = { "lmenu2", "lmenu2", "lmenu2", "lmenu2", "lmenu3", "lmenu2", "lmenu2" };
        private string[] strHeaderCss = { "", "", "NavIcon", "" };


        protected void Page_Load(object sender, EventArgs e)
        {
            string strUserIdFromCookie = Common.Cookie.getCookie("UserID");
            if (string.IsNullOrEmpty(strUserIdFromCookie))
            {
                Response.Redirect("/");
            }
            if (!Page.IsPostBack)
            {
                LoadInitialValue();
            }
        }

        private void LoadInitialValue()
        {
            string key = "VenuesId";
            string venuesIdString = Request.QueryString[key];
            if (!string.IsNullOrEmpty(venuesIdString))
            {
                venuesId = int.Parse(venuesIdString);
                ModuleId = venuesIdString;
                Jy123.BLL.Venues_Main BLLVenues = new Jy123.BLL.Venues_Main();

                Jy123.BLL.Module_Main BLLModuleMain = new Jy123.BLL.Module_Main();
                Jy123.BLL.Club.CModule BLLCModule = new Jy123.BLL.Club.CModule();
                Jy123.BLL.Public_Level BLLLevel = new Jy123.BLL.Public_Level();
                Jy123.BLL.User_Main BLLUser = new Jy123.BLL.User_Main();

                venues = BLLVenues.GetModel(venuesId);
                userId = venues.FUser.Value;
                user = BLLUser.GetModel(userId);
                level = BLLLevel.GetModel(venues.FLevel.Value);
                module = BLLModuleMain.GetModel(venuesId);
                BindHTML();
            }
            else
            {
                //找不到UserId，返回首页,目前暂时返回空值
            }
        }

        private void BindHTML()
        {
            string strHTML = Cache["modulerank"].ToString();
            Jy123.Web.AppCode.Module appModule = new Jy123.Web.AppCode.Module();
            string strHeader = Cache["header"].ToString();
            string headerString = appModule.BindHeader(strHeader, strHeaderCss);
            string strLeft = Cache["leftmenu"].ToString();
            string strLeftLi = Cache["leftmenuli"].ToString();
            string strTail = "?VenuesId=" + venues.ID.ToString();
            string[] strHref = { "MyVenues.aspx" + strTail, "UpdateVenues.aspx" + strTail, "VenuesRace.aspx" + strTail, "VenuesAnnexe.aspx" + strTail, "#", "VenuesRepair.aspx" + strTail, "VenuesHire.aspx" + strTail };
            string[] strNoRaceHref = { "MyVenues.aspx" + strTail, "UpdateVenues.aspx" + strTail, "javascript:$.moonbox.warning('您的赛场没有进行比赛！')", "VenuesAnnexe.aspx" + strTail, "#", "VenuesRepair.aspx" + strTail, "VenuesHire.aspx" + strTail };
            string leftMenuString;
            if (venues.VStatus == Convert.ToInt32(Jy123.BLL.Public.EnumConfig.VenuesStatus.Race))
            {
                leftMenuString = appModule.BindLeftMenu(strLeft, strLeftLi, strContent, strHref, strCss);
            }
            else
            {
                leftMenuString = appModule.BindLeftMenu(strLeft, strLeftLi, strContent, strNoRaceHref, strCss);
            }
            string strClub = Cache["contentclub"].ToString();
            string contentString = appModule.BindContentClub(strClub, module, venues, user, level);
            string strMain = Cache["mainmenu"].ToString();
            string strDiv = Cache["mainmenusubdiv"].ToString();
            string strLi = Cache["mainmenusubdivli"].ToString();
            string mainMenuString = appModule.BindMainMenu(strMain, strDiv, strLi, userId);

            strHTML = strHTML.Replace("$Header$", headerString);
            strHTML = strHTML.Replace("$MainMenu$", mainMenuString);
            strHTML = strHTML.Replace("$LeftMenu$", leftMenuString);
            strHTML = strHTML.Replace("$ContentClub$", contentString);
            strHTML = strHTML.Replace("$Footer$", Cache["footer"].ToString());
            strHTML = strHTML.Replace("$ModuleId$", venues.ID.ToString());
            strHTML = strHTML.Replace("$VenuesName$", venues.VName);
            Response.Write(strHTML);
        }
    }
}
